<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
	<title>我的订单</title>
</head>
<body>
	<!-- header.jsp -->
	<jsp:include page="../header.jsp"></jsp:include>
	<!-- /header.jsp -->

	<!-- SECTION -->
	<div class="section">
		<!-- container -->
		<div class="container">
			<!-- row -->
			<div class="row">
				<div class="col-md-12">
					<h3>${msg}</h3>
					<c:if test="${fn:length(orders) > 0}">
						<div class="table-responsive">
							<c:forEach items="${orders}" var="order" varStatus="n">
								<table class="table table-bordered">
									<caption>
										订单${n.count} -> 详情
										<c:if test="${order.state == 0}">
											<a href="${pageContext.request.contextPath}/order?method=payOrder&oid=${order.oid}" style="color: indianred;">
												<span>&nbsp;&nbsp; 去付款 &nbsp;&nbsp;</span>
											</a>
											<a href="${pageContext.request.contextPath}/order?method=deleteOrder&oid=${order.oid}" style="color: indianred;">
												<span> 删除订单 &nbsp;&nbsp;</span>
											</a>
										</c:if>
									</caption>
									<tbody>
										<tr style="font-weight: bold;">
											<td>订单所含商品</td>
											<td>订单状态</td>
											<td>订单金额</td>
											<td>下单时间</td>
											<td>订单编号</td>
										</tr>
										<tr>
											<td style="vertical-align: middle;">
												<table class="table table-bordered" style="text-align: center;">
													<tbody>
													<tr style="font-weight: bold;">
														<td>图片</td>
														<td>名称</td>
														<td>单价</td>
														<td>数量</td>
														<td>小计</td>
													</tr>
													<c:forEach items="${order.orderItems }" var="item">
														<tr>
															<td width="60" width="40%" style="vertical-align: middle;">
																<img src="${pageContext.request.contextPath}/${item.product.pimage}" width="70" height="60">
															</td>
															<td width="30%" style="vertical-align: middle;">
																<a target="_blank" href="${pageContext.request.contextPath}/product?method=productDetails&pid=${item.product.pid}">${item.product.pname}</a>
															</td>
															<td width="20%" style="vertical-align: middle;">
																￥${item.product.shop_price}
															</td>
															<td width="20%" style="vertical-align: middle;">
																	${item.count}
															</td>
															<td width="15%" style="vertical-align: middle;">
																<span class="subtotal">${item.subTotal}</span>
															</td>
														</tr>
													</c:forEach>
													</tbody>
												</table>
											</td>
											<td style="vertical-align: middle;color: red;">
												<c:choose>
													<c:when test="${order.state == 0}">
														未付款
													</c:when>
													<c:when test="${order.state == 1}">
														已付款
													</c:when>
													<c:when test="${order.state == 2}">
														已发货
													</c:when>
													<c:when test="${order.state == 3}">
														已完成
													</c:when>
												</c:choose>
											</td>
											<td style="vertical-align: middle;">
												￥${order.total}
											</td>
											<td style="vertical-align: middle;">
												<fmt:formatDate value="${order.ordertime}" pattern="yyyy-MM-dd hh:mm:ss"></fmt:formatDate>
											</td>
											<td style="vertical-align: middle;">
												${order.oid}
											</td>
										</tr>
										<c:if test="${order.state != 0}">
											<tr style="font-weight: bold;">
												<td>收货人</td>
												<td>联系电话</td>
												<td>收货地址</td>

												<c:if test="${order.state == 1}">
													<td rowspan="2" colspan="2" width="10%" style="vertical-align: middle;text-align: center;">
														待商家发货
													</td>
												</c:if>

												<c:if test="${order.state == 2}">
													<td rowspan="2" colspan="2" width="10%" style="vertical-align: middle;text-align: center;">
														<button class="btn btn-danger" onclick="finishOrder('${order.oid}')">确认收货</button>
													</td>
												</c:if>

												<c:if test="${order.state == 3}">
													<td rowspan="2" colspan="2" width="10%" style="vertical-align: middle;text-align: center;">
														恭喜你完成本次购物，欢迎再次光临
													</td>
												</c:if>
											</tr>
											<tr>
												<td width="30%" style="vertical-align: middle;">
													${order.name}
												</td>
												<td width="30%" style="vertical-align: middle;">
													${order.telephone}
												</td>
												<td width="30%" style="vertical-align: middle;">
													${order.address}
												</td>
											</tr>
										</c:if>
									</tbody>
								</table>
							</c:forEach>
						</div>
					</c:if>
					<c:if test="${fn:length(orders) <= 0}">
						<h3>暂无订单数据，请<a href="${pageContext.request.contextPath}/">接着逛逛</a></h3>
					</c:if>
				</div>
			</div>
			<!-- /row -->
		</div>
		<!-- /container -->
	</div>
	<!-- /SECTION -->

	<!-- footer.jsp -->
	<jsp:include page="../footer.jsp"></jsp:include>
	<!-- /footer.jsp -->

</body>
</html>
